/**
 * 获取命令行的参数
 * @param prefix 前缀
 */
import {promisify} from "node:util"
import childProcess from "node:child_process"
export function getParams(prefix = '-'): { [k: string]: string | true } {
  return process.argv.slice(2).reduce((obj, it) => {
    const sp = it.split('=');
    const key = sp[0].replace(prefix, '');
    obj[key] = sp[1] || true;
    return obj;
  }, {} as ReturnType<typeof getParams>);
}

export const exec = promisify(childProcess.exec);
export async function execute(cmd: string): Promise<string> {
    console.log('------执行"' + cmd + '"命令...-------');
    const {stdout} = await exec(cmd);
    console.log('stdout: ', stdout);
    return stdout;
}

export async function mulExec(command: string[]) {
    for (const cmd of command) {
        await execute(cmd);
    }
}
